﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ornament.Messages;
using Ornament.Messages.Dao;
using Ornament.MVCWebFrame.Models;
using Ornament.Web;
using Ornament.Web.Mvc;

namespace Ornament.MVCWebFrame.Areas.Infos.Controllers
{
    public class ManageController : Controller
    {
        //
        // GET: /Infos/Infos/Index/pageIndex-pageSize
        public ActionResult Index(string pages)
        {
            int page = 0;
            int pageSize = 40;
            if (pages != null)
            {
                string[] ary = pages.Split('-');
                page = Convert.ToInt32(ary[0]);
                pageSize = Convert.ToInt32(ary[1]);
            }
            IList<Info> result = OrnamentContext.Current.MessageManager.Factory.InfoDao.FindAll(page, pageSize);
            ViewData["list"] = result;
            return View();
        }

        public ActionResult ReaderList(Guid? id)
        {
            Info info = OrnamentContext.Current.MessageManager.Factory.InfoDao.Get(id.Value);
            ViewData["infoStates"] = info != null
                                         ? (IEnumerable<InfoReader>)info.Readers
                                         : new List<InfoReader>();
            return View();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(Guid? id)
        {
            return View(OrnamentContext.Current.MessageManager.Factory.InfoDao.Get(id.Value));
        }
       
       
    }
}